class <%= controller_class %> < ApplicationController
  def create
    @<%= payable %> = <%= payable_class %>.create!(create_params)
    srv = PuntoPagosRails::TransactionService.new(@<%= payable %>)
    srv.create ? redirect_to(srv.process_url) : render(:error)
  end

  def notification
<% if ssl? -%>
    response = PuntoPagosRails::TransactionService.notificate(params, request.headers)
    render json: response
<% else -%>
    PuntoPagosRails::TransactionService.complete(params)
    head(200)
<% end -%>
  end

  def success
    @<%= payable %> = PuntoPagosRails::TransactionService.<%= payable %>_by_token(params)
  end

  def error
    @<%= payable %> = PuntoPagosRails::TransactionService.failed_<%= payable %>_by_token(params)
  end

  private

  def create_params
    params.require(:<%= payable %>).permit(:amount)
  end
end
